package com.git_taoxian.test4;

import java.io.BufferedInputStream;
import java.io.FileInputStream;
import java.io.OutputStream;
import java.net.Socket;
import java.util.concurrent.Callable;

public class MyCallable implements Callable {
    private Socket socket;

    public MyCallable() {
    }
    public MyCallable(Socket socket) {
        this.socket = socket;
    }

    @Override
    public Object call() throws Exception {
//        获取输出流对象
        OutputStream os = socket.getOutputStream();
        //        循环读取文件夹里面的文件
        BufferedInputStream bis = new BufferedInputStream(new FileInputStream("d:/java/tx.txt"));
        byte[] buf = new byte[3];//每次读3个字节
        int len;
        while ((len = bis.read(buf)) != -1) {
            os.write(buf, 0, len);
        }
        bis.close();
        os.close();
        socket.close();
        return null;
    }
}
